package com.shengcheng.controller;

import com.shengcheng.login.TingShuLogin;
import com.shengcheng.result.RetVal;
import com.shengcheng.service.PaymentInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 付款信息表 前端控制器
 * </p>
 *
 * @author 强哥
 * @since 2023-12-19
 */
@Tag(name = "微信支付接口")
@RestController
@RequestMapping("api/payment/wxPay")
@Slf4j
public class PaymentInfoController {
    @Autowired
    private PaymentInfoService paymentInfoService;

    @TingShuLogin
    @Operation(summary = "微信下单并返回二维码")
    @PostMapping("createJsapi/{paymentType}/{orderNo}")
    public RetVal saveOrderAndDetail(@PathVariable String paymentType, @PathVariable String orderNo) {
        return paymentInfoService.saveOrderAndDetail(paymentType,orderNo);
    }
    @Operation(summary = "微信支付成功异步调用接口 如果开了魔法-这个地方容易不过来")
    @PostMapping("asyncNotify")
    public RetVal asyncNotify(HttpServletRequest request) {
        paymentInfoService.asyncNotify(request);
        return RetVal.ok();
    }
    //http://127.0.0.1/api/payment/wxPay/queryPayStatus/155c382e27
    @Operation(summary = "查询支付状态")
    @GetMapping("queryPayStatus/{orderNo}")
    public RetVal queryPayStatus(@PathVariable String orderNo) {
        return paymentInfoService.queryPayStatus(orderNo);
    }
}
